﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace MyWcfRestLib.Files
{
    class DeleteFileOperator : FileOperator
    {
        public DeleteFileOperator(OnePathOpParams theParams)
            : base(theParams)
        {
            DeletingFullPath = Path.Combine(DeviceRootFullPath, theParams.WorkingPath);
        }

        public string DeletingFullPath { get; private set; }
        public bool IsPathExist { get { return UtilityFunctions.PathExists(DeletingFullPath); } }

        public override bool CanPerform
        {
            get { return IsPathExist; }
        }

        public override bool PerformOperation()
        {
            if (!CanPerform)
                return false;

            try
            {
                if (UtilityFunctions.IsDir(DeletingFullPath))
                {
                    Directory.Delete(DeletingFullPath, true);
                }
                else
                {
                    File.Delete(DeletingFullPath);
                }
                return true;
            }
            catch (IOException)
            {
                return false;
            }

        }

    }
}
